﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
using CNotebook.Purchases;


namespace NotebookS2
{
    public partial class FND_CASHDISBURSE_GRPO : RibbonForm
    {
        public FND_CASHDISBURSE_GRPO()
        {
            InitializeComponent();
        }
        public string ConnectionString { get; set; }
        public string DocumentNumber { get; set; }
        public DateTime DocumentDate { get; set; }
        public string RefInvoiceNumber { get; set; }
        public string VendorCode { get; set; }
        public string VendorName { get; set; }
        public double NetAmount { get; set; }

        void BindGridByDocument(string _DocNumber)
        {
            GoodsReceivingReportManager oManager = new GoodsReceivingReportManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            gridControl1.DataSource = oManager.GetPostedReceivingReport(this.VendorCode, _DocNumber);
            gridControl1.Refresh();

            oManager.Close();
        }
        private void txtBPCode_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }

        private void FND_GRPO_Load(object sender, EventArgs e)
        {

        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int iRowIndex = gridView1.FocusedRowHandle;

            this.DocumentNumber = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["DocNum"]).ToString();
            this.RefInvoiceNumber = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["SupplierInvoice"]).ToString();
            this.DocumentDate = Convert.ToDateTime(gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["PostingDate"]).ToString());
            this.NetAmount = Convert.ToDouble(gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["Balance"]).ToString());
            this.VendorCode = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["CardCode"]).ToString();
            this.VendorName = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["CardName"]).ToString();


            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtSearch_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            BindGridByDocument(txtSearch.Text);
        }

        private void FND_GRPO_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }

        private void txtSearch_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                BindGridByDocument(txtSearch.Text);
            }
            if (e.KeyCode == Keys.Tab)
            {
                BindGridByDocument(txtSearch.Text);
            }
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
            if (e.KeyCode == Keys.Tab)
            {
                btnChoose_Click(sender, e);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }
    }
}
